package br.biofoco.p2p.peer;

import java.io.IOException;
import java.util.Collection;
import java.util.Map;

import br.biofoco.p2p.dht.DHTService;
import br.biofoco.p2p.rpc.EndPoint;
import br.biofoco.p2p.rpc.Protocol;
import br.biofoco.p2p.rpc.service.Messenger;

import com.google.common.collect.Maps;

public class ProxyPeer implements PeerNode {
	
	private final ID peerID;
	private final PeerConfig config;
	private final Map<Protocol,EndPoint> endpoints = Maps.newEnumMap(Protocol.class);
	
	public ProxyPeer(PeerConfig config) {
		this.config = config;
		this.peerID = config.getPeerID();
		for (EndPoint ep : config.getEndPoints()) {
			endpoints.put(ep.getProtocol(), ep);
		}
	}
	
	public void addEndPoint(EndPoint endpoint) {
		endpoints.put(endpoint.getProtocol(), endpoint);
	}
	
	public Collection<EndPoint> getEndpoints() {
		return endpoints.values();
	}
	
	public PeerConfig getConfig() {
		return config;
	}

	@Override
	public EndPoint getEndPoint(Protocol protocol) {
		return endpoints.get(protocol);
	}

	@Override
	public Collection<EndPoint> getEndPoints() {
		return endpoints.values();
	}

	@Override
	public PeerConfig getPeerConfig() {
		return config;
	}

	@Override
	public ID getPeerID() {
		return peerID;
	}

	@Override
	public void start() throws IOException {
		throw new UnsupportedOperationException("Operation not supported!");
	}

	@Override
	public void stop() throws IOException {
		throw new UnsupportedOperationException("Operation not supported!");		
	}
	
	@Override
	public String toString() {
		return peerID + ":" + endpoints;
	}

	@Override
	public Messenger getMessenger() {
		throw new UnsupportedOperationException("Operation not supported!");	
	}

	@Override
	public Collection<PeerNode> getPeerView() {
		throw new UnsupportedOperationException("Operation not supported!");	
	}

}
